<template>
  <view class="perception" v-if="listv.data">
    <view
      class="perception_item"
      v-for="(item, index) in listv.data"
      :key="index"
      @click="goDetail(item)"
    >
      <view class="item_t">
        <view class="perception_t_left">
          <image
            :src="item.user.avatar_url"
            mode=""
            @click.stop="goHome(item.user.user_id)"
          ></image>
          <text class="perception_t_text">{{ item.user.nick_name }}</text>
        </view>

        <view
          v-show="!flag"
          class="item_left_clickView"
          @click.stop="change(item)"
        >
          <image
            v-if="!item.clickable"
            class="item_left_click"
            src="../static/images/my/icon_grzy_quanxuan.png"
            mode=""
          ></image>
          <image
            v-else
            class="item_left_clickable"
            src="../static/images/my/icon_grzy_xc_xuanzhong.png"
            mode=""
          ></image>
        </view>
      </view>

      <view class="all_detail" >
        <view class="item_c">
          <view class="perception_c_left" :class="my_level_id < item.grade_auth ? 'card_content1' : ''" v-html="item.content || item.msg">
            <!-- {{ item.content || item.msg }} -->
          </view>
          <view
            class="card_content_box_preview"
            v-if="my_level_id < item.grade_auth"
            @click.stop="goMember"
          >
            该内容仅支持{{
              item.grade_auth == 1
                ? "元气驿站"
                : item.grade_auth == 2
                ? "启初梦谷"
                : item.grade_auth == 3
                ? "青空天台"
                : item.grade_auth == 4
                ? "无极云顶"
                : item.grade_auth == 5
                ? "返朴归源"
                : ""
            }}及以上行者查看
          </view>
        </view>
        <view class="item_b" v-if="!item.msg">
          <view class="zanping_view" v-if="showZanPing">
            <view class="zanBtn" @click="dianZan()">
              <image
                class="zanImg"
                src="@/static/weichuang/icon_fld_dianzan.png"
              ></image>
              <view class="zanFont" style="margin-right: 43rpx">{{
                item.like_count
              }}</view>
            </view>
            <view class="zanBtn" @click="pinglun()">
              <image
                class="zanImg"
                src="@/static/weichuang/icon_fld_pinglun.png"
              ></image>
              <view class="zanFont">{{ item.comment_count }}</view>
            </view>
          </view>
          <view class="time_view">{{ item.create_time }}</view>
        </view>
      </view>

      <!-- 预览样式 -->
      <!-- <view class="Preview_style" v-else @click.stop="goMember">
        该内容仅支持{{
          item.grade_auth == 1
            ? "元气驿站"
            : item.grade_auth == 2
            ? "启初梦谷"
            : item.grade_auth == 3
            ? "青空天台"
            : item.grade_auth == 4
            ? "无极云顶"
            : item.grade_auth == 5
            ? "返朴归源"
            : ""
        }}及以上行者查看
      </view> -->
    </view>

    <view class="bottom" v-show="!flag">
      <view class="bottom_left">
        <view @click="changeClick">
          <image
            v-if="!clickableAll"
            class="item_left_click"
            src="../static/images/my/icon_grzy_quanxuan.png"
            mode=""
          ></image>
          <image
            v-else
            class="item_left_click"
            src="../static/images/my/icon_grzy_xc_xuanzhong.png"
            mode=""
          ></image>
        </view>
        <view class="bottom_left_text">全选</view>
      </view>
      <view class="bottom_right" @click="deleteFn">删除</view>
    </view>

    <u-modal
      :show="show"
      :title="title"
      :content="content"
      confirmColor="#55B877"
      :closeOnClickOverlay="true"
      @confirm="confirm"
      @close="close"
      @cancel="cancel"
      :showCancelButton="true"
    ></u-modal>

    <view class="empty_view" v-if="listv.data && listv.data.length == 0">
      <image
        class="item_left_clickable"
        src="../static/images/my/kong.png"
        mode=""
      ></image>
      <view v-if="from == 'history'">您还没有历史记录~</view>
      <view v-else>当前没有相关数据，请查看其他分类或功能。</view>
    </view>
  </view>
</template>
  
  <script>
export default {
  components: {},
  props: {
    flag: {
      type: Boolean,
      default: true,
    },
    list: {
      type: Object,
      default: {},
    },
    showZanPing: {
      type: Boolean,
      default: true,
    },
    from: {
      type: String,
      default: "",
    },
    my_level_id: {
      type: Number,
      default: 0,
    },
  },
  watch: {
    list: {
      deep: true, // 深度监听每一个属性值, 如果是对象可以深度监听
      immediate: true, // 进入页面后立即自动调用handler函数
      handler(newValue) {
        this.listv = newValue;
        if (this.listv.data) {
          for (let i = 0; i < this.listv.data.length; i++) {
            this.listv.data[i].clickable = false;
          }
        }
        console.log(this.listv.data, "newList");
      },
    },
  },
  data() {
    return {
      clickableAll: false,
      listv: [],
      show: false,
      title: "确认删除",
      content: "确认删除选中内容？",
    };
  },
  methods: {
    goHome(user_id) {
      uni.navigateTo({
        url: `/pages/home/home?user_id=${user_id}`,
      });
    },
    // 跳会员页面
    goMember() {
      uni.navigateTo({
        url: `/pages/member/index`,
      });
    },
    goDetail(item) {
      uni.navigateTo({
        url: `/pages/detail/flyDetail?detailType=youji&currentId=${item.id}&from=wei`,
      });
    },
    change(item) {
      this.$forceUpdate();
      item.clickable = !item.clickable;
      // 判断是否全选
      let all = true;
      for (let i = 0; i < this.listv.data.length; i++) {
        if (this.listv.data[i].clickable == false) {
          all = false;
        }
      }
      if (all) {
        this.clickableAll = true;
      } else {
        this.clickableAll = false;
      }
    },
    changeClick() {
      this.clickableAll = !this.clickableAll;
      if (this.clickableAll) {
        for (let i = 0; i < this.listv.data.length; i++) {
          this.listv.data[i].clickable = true;
        }
      } else {
        for (let i = 0; i < this.listv.data.length; i++) {
          this.listv.data[i].clickable = false;
        }
      }
    },
    confirm() {
      this.show = false;
      let arr = [];
      let num = 0;
      for (let i = 0; i < this.listv.data.length; i++) {
        if (this.listv.data[i].clickable == true) {
          arr.push(this.listv.data[i].history_id);
          num++;
        }
      }
      console.log(arr, "数组");
      this.deletFn(arr);
    },
    close() {
      this.show = false;
    },
    cancel() {
      this.show = false;
    },
    pinglun() {},
    dianZan() {},
    // 删除按钮
    deleteFn() {
      let isTrue = true;
      for (let i = 0; i < this.listv.data.length; i++) {
        if (this.listv.data[i].clickable == true) {
          isTrue = false;
        }
      }
      if (isTrue == true) {
        uni.$u.toast("您还未选择内容");
      } else {
        this.show = true;
      }
    },
    // 删除接口
    deletFn(arr) {
      this.$http
        .historyDel_his_weichuang({ ids: arr })
        .then((res) => {
          uni.$u.toast(res.message);
          this.show = false;
          setTimeout(() => {
            this.$emit("updateDataYouJi");
          }, 1000);
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
  },
};
</script>
  
  <style scoped lang="scss">
.perception {
  width: 100%;
  border-radius: 16rpx 16rpx 16rpx 16rpx;
  padding: 0 30rpx;
  box-sizing: border-box;

  .perception_item {
    width: 100%;
    padding: 32rpx;
    box-sizing: border-box;
    margin-top: 32rpx;
    background: rgba(39, 39, 39, 0.5);
    .item_t {
      width: 100%;
      display: flex;
      justify-content: space-between;

      .perception_t_left {
        display: flex;
        align-items: center;

        image {
          width: 72rpx;
          height: 72rpx;
          border-radius: 50%;
        }

        .perception_t_text {
          font-size: 28rpx;
          font-family: PingFang SC, PingFang SC;
          font-weight: 400;
          color: #eeeeee;
          margin-left: 24rpx;
        }
      }

      .perception_t_right {
        width: 142rpx;
        height: 56rpx;
        border-radius: 32rpx;
        background: rgba(85, 184, 119, 0.1);
        border: 1rpx solid #55b877;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 26rpx;
        font-family: PingFang SC, PingFang SC;
        font-weight: 400;
        color: #55b877;
      }
      .item_left_clickView {
        margin-right: 24rpx;
        .item_left_click {
          width: 40rpx;
          height: 40rpx;
        }
        .item_left_clickable {
          width: 40rpx;
          height: 40rpx;
        }
      }
    }


    .all_detail{

    }

    .Preview_style{
      width: 100%;
      height: 300rpx;
      border-radius: 16rpx;
      background: rgba(105, 113, 151, 0.7);
      margin-top: 24rpx;
      text-align: center;
      line-height: 300rpx;
      color: white;
    }



    .item_c {
      width: 100%;
      margin-top: 16rpx;
      display: flex;
      position: relative;
      .perception_c_left {
        font-size: 30rpx;
        font-family: PingFang SC, PingFang SC;
        font-weight: 400;
        color: #eeeeee;
        word-break: break-word; //换行模式
        overflow: hidden;
        text-overflow: ellipsis; //修剪文字，超过2行显示省略号
        display: -webkit-box;
        -webkit-line-clamp: 2; //此处为上限行数
        -webkit-box-orient: vertical;
      }
      .card_content1 {
      height: 114rpx;
    }
      .perception_c_right {
        width: 96rpx;
        height: 96rpx;
        margin-left: 24rpx;
        image {
          width: 100%;
          height: 100%;
        }
      }
      .card_content_box_preview {
        color: #eeeeee;
        padding-top: 30rpx;
        box-sizing: border-box;
        position: absolute;
        top: 0;
        background: linear-gradient(
          360deg,
          rgba(48, 53, 77, 1) 50%,
          rgba(49, 57, 79, 0) 100%
        );
        text-align: center;
        width: 100%;
        height: 100%;
      }
    }
    .item_b {
      width: 100%;
      display: flex;
      margin-top: 16rpx;
      justify-content: space-between;
      .zanping_view {
        display: flex;
        .zanBtn {
          display: flex;
          align-items: center;
          .zanImg {
            width: 40rpx;
            height: 40rpx;
          }
          .zanFont {
            margin: 0 10rpx;
            line-height: 40rpx;
            font-size: 24rpx;
            color: #adadad;
          }
        }
      }
      .time_view {
        font-size: 24rpx;
        color: #adadad;
      }
    }
  }

  .bottom {
    width: 100%;
    height: 112rpx;
    background: #272727;
    position: fixed;
    bottom: 0;
    left: 0;
    padding: 16rpx 30rpx;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .bottom_left {
      display: flex;
      align-items: center;
      .item_left_click {
        width: 40rpx;
        height: 40rpx;
      }
      .bottom_left_text {
        margin-left: 16rpx;
        color: #eeeeee;
        font-size: 30rpx;
      }
    }

    .bottom_right {
      width: 250rpx;
      height: 80rpx;
      background: #ee6060;
      border-radius: 48rpx;
      text-align: center;
      line-height: 80rpx;
      font-size: 30rpx;
      color: #eeeeee;
    }
  }

  /deep/.u-modal__content__text {
    text-align: center;
  }

  .empty_view {
    margin-top: 300rpx;
    image {
      margin: 0 auto;
      width: 410rpx;
      height: 410rpx;
    }
    view {
      font-size: 30rpx;
      color: #d8d8d8;
      text-align: center;
    }
  }
}
</style>